/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.querie.SI;
import com.querie.Voldemort.VoldemortH;
import com.querie.beans.SessionS;
import com.querie.beans.ItemS;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;


import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author Naushin
 */
public class PutItemData {
        VoldemortH vold=new VoldemortH();
        Gson gson=new Gson();
        /**
         * put the data in stores with primary key as id1
         * @param id1: is the unique identifier of a row
         * @param S: list of session names
         * @param SC: list of corresponding counts
         */
        public void putAll(int id1, List<Integer> S, List<Integer> SC){
            List<SessionS> list=new ArrayList<SessionS>();
            List<Integer> list1=new ArrayList<Integer>();
            String id2=Integer.toString(id1);
            /*String present=vold.getValue(id2, "ItemA");
            if(present!=null){
            return;
            }
             else if (present==null)*/
            System.out.println("in put all");

            ItemS iS=new ItemS();
            for(int k=0;k<S.size();k++){
            SessionS sall=new SessionS();
            sall.setSessionName(S.get(k));
            //System.out.println(S.get(k));
            sall.setSessionCount(SC.get(k));
            //System.out.println(SC.get(k));
            list.add(sall);
     }

            iS.setSession(list);
            iS.setItemName(id1);
            list1.add(id1);



        try{
            String iAllValue= gson.toJson(iS);
            vold.putValue(""+id1,iAllValue, "ItemThree");
           // System.out.println(iAllValue);
        }catch (Exception ex){
           System.out.println("Exception: "+ex);
        }



System.out.println("ItemList Added");
System.out.println("Item id generated: "+id1);


return;
    }
/* public void putData(){
 putAll();
 }*/

         public void delete(){
            VoldemortH v=new VoldemortH();
            v.delValue(Integer.toString(7750), "ItemThree");//itemtwooo
            }
         public void checkIfInserted(){
            VoldemortH vh= new VoldemortH();
            String iA=vh.getValue("7836","ItemThree");
            if(iA==null){
            System.out.println("Item not present");

             }

            else System.out.println("Element found"+iA);
            }
public static void main(String[] args){
    PutItemData pd1 = new PutItemData();
  //  pd1.putData();
  //  pd1.putAll(id1, null, null);
  pd1.checkIfInserted();
  
 }
}
